import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/hd',
    name: 'Table',
    meta: {
      title: '基础设置',
      icon: 'table'
    },
    children: [
      {
        path: 'hd',
        component: () => import('@/views/documentation/hd'),
        name: 'Documentation',
        meta: { title: '弹窗图片', icon: 'el-icon-picture-outline' }
      },
      {
        path: 'config',
        component: () => import('@/views/documentation/config'),
        name: 'Documentation',
        meta: { title: '商城配置', icon: 'documentation' }
      },
      {
        path: 'index',
        component: () => import('@/views/zf/index'),
        name: 'zf',
        meta: { title: '支付配置', icon: 'documentation' }
      },
      {
        path: 'banlist',
        component: () => import('@/views/banlist/index'),
        name: 'banlist',
        meta: { title: '轮播图', icon: 'guide' }
      },
    ]
  },
  {
    path: '/documentation',
    component: Layout,
    name: 'Users',
    meta: {
      title: '会员管理',
      icon: 'table'
    },
    children: [
      // {
      //   path: 'index',
      //   component: () => import('@/views/documentation/index'),
      //   name: 'Documentation',
      //   meta: { title: '会员等级', icon: 'documentation' }
      // },
      {
        path: 'index',
        component: () => import('@/views/documentation/index'),
        name: 'Documentation',
        meta: { title: '普通会员', icon: 'documentation' }
      },
      {
        path: 'indexpt',
        component: () => import('@/views/documentation/indexpt'),
        name: 'indexpt',
        meta: { title: '付费会员', icon: 'documentation' }
      }
    ]
  },
  {
    path: '/hq',
    component: Layout,
    redirect: '/hqindex',
    name: 'fxindex',
    meta: {
      title: '金属行情',
      icon: 'table'
    },
    children: [
      {
        path: 'clist',
        component: () => import('@/views/jshq/clist'),
        name: 'clist',
        meta: { title: '分类管理', icon: 'guide' }
      },
      {
        path: 'citys',
        component: () => import('@/views/jshq/citys'),
        name: 'citys',
        meta: { title: '城市管理', icon: 'guide' }
      },
      {
        path: 'zxlist',
        component: () => import('@/views/jshq/zxlist'),
        name: 'zxlist',
        meta: { title: '行情管理', icon: 'guide' }
      },
      {
        path: 'index',
        component: () => import('@/views/jshq/index'),
        name: 'index',
        meta: { title: '市场情报', icon: 'guide' }
      }
    ]
  },
  {
    path: '/admins',
    component: Layout,
    redirect: '/admins/index',
    name: 'Admins',
    meta: {
      title: '商家管理',
      icon: 'table'
    },
    children: [
      {
        path: 'addshop',
        component: () => import('@/views/shop/addshop'),
        name: 'Guide',
        meta: { title: '入驻管理', icon: 'guide' }
      }, {
        path: 'index',
        component: () => import('@/views/shop/index'),
        name: 'Guide',
        meta: { title: '商家管理', icon: 'guide' }
      }
      // , {
      //   path: 'index',
      //   component: () => import('@/views/admins/index'),
      //   name: 'Guide',
      //   meta: { title: '管理员管理', icon: 'guide' }
      // }
    ]
  },
  {
    path: '/cindex',
    component: Layout,
    redirect: '/cindex',
    name: 'Hy',
    meta: {
      title: '货源管理',
      icon: 'table'
    },
    children: [
      {
        path: 'cindex',
        component: () => import('@/views/clist/index'),
        name: 'cindex',
        meta: { title: '分类管理', icon: 'guide' }
      },
      {
        path: 'hyindex',
        component: () => import('@/views/hy/index'),
        name: 'hyindex',
        meta: { title: '回收管理', icon: 'guide' }
      },
      {
        path: 'zbindex',
        component: () => import('@/views/zb/index'),
        name: 'zbindex',
        meta: { title: '招标管理', icon: 'guide' }
      },
      {
        path: 'cgindex',
        component: () => import('@/views/cg/index'),
        name: 'cgindex',
        meta: { title: '求购管理', icon: 'guide' }
      }
    ]
  },
  {
    path: '/shopindex',
    component: Layout,
    redirect: '/shopindex',
    name: 'shopindex',
    meta: {
      title: '商城管理',
      icon: 'table'
    },
    children: [
      {
        path: 'shopclist',
        component: () => import('@/views/orders/oclist'),
        name: 'shopclist',
        meta: { title: '商品分类', icon: 'guide' }
      },
      {
        path: 'obanlist',
        component: () => import('@/views/orders/obanlist'),
        name: 'obanlist',
        meta: { title: '商城轮播图', icon: 'guide' }
      },
      // {
      //   path: 'ocfing',
      //   component: () => import('@/views/orders/ocfing'),
      //   name: 'ocfing',
      //   meta: { title: '商城配置', icon: 'guide' }
      // },
      {
        path: 'goods',
        component: () => import('@/views/orders/goods'),
        name: 'goods',
        meta: { title: '商品管理', icon: 'guide' }
      },
      {
        path: 'shopindex',
        component: () => import('@/views/orders/index'),
        name: 'shopindex',
        meta: { title: '订单管理', icon: 'guide' }
      },
    ]
  },
  {
    path: '/fx',
    component: Layout,
    redirect: '/fxindex',
    name: 'fxindex',
    meta: {
      title: '分销管理',
      icon: 'table'
    },
    children: [
      {
        path: 'fxconfig',
        component: () => import('@/views/fx/fxconfig'),
        name: 'fxconfig',
        meta: { title: '分销配置', icon: 'guide' }
      },
      {
        path: 'fxindex',
        component: () => import('@/views/fx/index'),
        name: 'fxindex',
        meta: { title: '分销商管理', icon: 'guide' }
      },

      {
        path: 'tx',
        component: () => import('@/views/fx/tx'),
        name: 'tx',
        meta: { title: '提现管理', icon: 'guide' }
      }
    ]
  },





  // {
  //   path: '/banlist',
  //   component: Layout,
  //   redirect: '/banlist/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/banlist/index'),
  //       name: 'banlist',
  //       meta: { title: '轮播图', icon: 'guide' }
  //     }
  //   ]
  // },

  {
    path: '/zb',
    component: Layout,
    redirect: '/zb/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/zb/index'),
        name: 'zb',
        meta: { title: '招标', icon: 'guide' }
      }
    ]
  }, {
    path: '/cg',
    component: Layout,
    redirect: '/cg/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/cg/index'),
        name: 'zb',
        meta: { title: '采购', icon: 'guide' }
      }
    ]
  },
]
/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
